class GitCodeUser {
  final int id;
  final String login;
  final String name;
  final String? avatarUrl;
  final String? bio;
  final int publicRepos;
  final int followers;
  final int following;

  GitCodeUser({
    required this.id,
    required this.login,
    required this.name,
    this.avatarUrl,
    this.bio,
    required this.publicRepos,
    required this.followers,
    required this.following,
  });

  factory GitCodeUser.fromJson(Map<String, dynamic> json) {
    int parseInt(dynamic v) {
      if (v is int) return v;
      if (v is String) return int.tryParse(v) ?? 0;
      return 0;
    }

    return GitCodeUser(
      id: parseInt(json['id']),
      login: json['login'] ?? '',
      name: json['name'] ?? '',
      avatarUrl: json['avatar_url'],
      bio: json['bio'],
      publicRepos: parseInt(json['public_repos']),
      followers: parseInt(json['followers']),
      following: parseInt(json['following']),
    );
  }
}